"use strict";
const { Model } = require("sequelize");
const moment = require("moment");
moment.locale("zh-cn");
module.exports = (sequelize, DataTypes) => {
  class Config extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
    }
  }
  Config.init(
    {
      ip: DataTypes.STRING,
      port: DataTypes.STRING,
      status: DataTypes.STRING,
      type: DataTypes.STRING,
      beUsed: DataTypes.STRING,
      createdAt: {
        type: DataTypes.DATE,
        get() {
          // 为了解决服务器端返回的时间格式 时区不一致的问题
          return moment(this.getDataValue("createdAt")).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        },
      },
      updatedAt: {
        type: DataTypes.DATE,
        get() {
          return moment(this.getDataValue("updatedAt")).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        },
      },
    },
    {
      sequelize,
      modelName: "Config",
    }
  );
  return Config;
};
